
public class SoundControler {

	private double outputVolume = 0.5;

	private Thread musicThread;
	private SoundThread music;
	private Boolean stopMusic = false;

	private Thread fxThread;
	private SoundThread fx;

	public void playSong(String filename) {
		this.stopMusic = false;
		if(filename == null)
			filename = "preview.wav";
		this.music = new SoundThread(filename);
		this.music.setDefaultVolume(this.outputVolume);
		this.musicThread = new Thread(music);
		this.musicThread.start();
	}

	public void playFX(String filename) {
		this.fx = new SoundThread(filename);
		this.fx.setDefaultVolume(this.outputVolume);
		this.fxThread = new Thread(fx);
		this.fxThread.start();
	}

	public void updateMusic(){
		if(!musicThread.isAlive() && !stopMusic)
			this.playSong("preview.wav");
		if(stopMusic && music.getVolume() > 0)
			music.setVolume(music.getVolume()-0.01);
		if(music.getVolume() <= 0) {
			music.kill();
		}
	}

	public void killMusic() {
		this.stopMusic = true;
	}

	public void setOutputVolume(double outputVolume) {
		this.outputVolume = outputVolume;
		this.music.setVolume(outputVolume);
	}

	public double getOutputVolume() {
		return this.outputVolume;
	}

}
